<?php

	/* description	: system configuration center
	 * developer	: BREEZEER
	 * release date	: 2022.10.31
	 * version		: 1.0.0
	 *
	 *
	 */
    namespace App\common;

	use Illuminate\Support\Facades\DB;
	
	/* get debug flag from url address => v_debug
	 *
	 *												0. true => enable debug
	 *												1. false => disabled
	 *
	 *
	 */
	define('define_debug_mode',app()->request->v_debug=='yes'?true:false);
	 
	/* testing implements 
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 */
	class cTesting
	{
		public function __construct()
		{
			$this->m_cHelper	= app()->gcHelper;
		}

		public function go()
		{
			# debug switch
			#
			#
			if(define_debug_mode===true)
			{
			}
			else
			{
				return;
			}

			# go testing code
			#
			#
			$this->go_testing_start();$this->go_testing();$this->go_testing_end();
		}
		private function go_testing_start()
		{
		}
		private function go_testing_end()
		{
			die;
		}

		/* go testing ..........
		 *
		 *
		 *
		 *
		 */
		private function go_testing()
		{
			$this->go_testing_miscellaneous_environment_parameter();
			$this->go_testing_mysql();
			# $this->go_testing_mulit_database_query();
			# $this->go_testing_redis();
		}
		private function go_testing_mulit_database_query()
		{
			$this->m_cHelper->gfDbQueryInMultiDB	(
														'
															select 
																	database()
																	,(select substring_index(host,":",1) from information_schema.processlist where ID = connection_id() ) as ip
																	,@@port 
																	,user() 
																	,SYSTEM_USER()
																	,CURRENT_USER()
																	,VERSION()
																	,week(now())
																	,decode(ENCODE("123","aaa"),"aaa"),md5(encode("aaaaa","key")),AES_DECRYPT(AES_ENCRYPT("123","key"),"key")
														'
													)
							->forEachRow			(
														function($row)
														{
															$this->m_cHelper->gfDebugPrint ($row,kill:false);
														}
													);
		}
		private function go_testing_mysql()
		{
			$this->m_cHelper->gfDbQuery()->select	
			(
				'
					select 
							database()
							,(select substring_index(host,":",1) from information_schema.processlist where ID = connection_id() ) as ip
							,@@port 
							,user() 
							,SYSTEM_USER()
							,CURRENT_USER()
							,VERSION()
							,week(now())
							,decode(ENCODE("123","aaa"),"aaa"),md5(encode("aaaaa","key")),AES_DECRYPT(AES_ENCRYPT("123","key"),"key")
				'
			)
			->forEachRow
			(
				function ($row)
				{
					$row->appendItem(['medation'=>'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm']);

					return $row->getOneRowAllData();
				}
				,
				$ar
			);
			
			$this->m_cHelper->gfDebugPrint ($ar,kill:false);
		}
		private function go_testing_miscellaneous_environment_parameter()
		{
			$this->m_cHelper->gfDebugPrint	(
												[
													'com_id'									=>	app()->request->get('com_id')
													,
													'get_request_header_value_test:User-Agent'	=>	$this->m_cHelper->gfGetValueFromHeader('User-Agent')
												]
												,kill:false
											);
		}
		private function go_testing_redis()
		{
			$this->m_cHelper->gfDebugPrint	(
												[
													'redis'										=>	[
																										app()->gcHelper->gfGetRedis()
																																		->list("xxx.list")
																																							->push($this->m_cHelper->gfGetCurrentLocalDate()." 000")
																																							->push($this->m_cHelper->gfGetCurrentLocalDate()." 001")
																																							->push($this->m_cHelper->gfGetCurrentLocalDate()." 002")
																																							->push($this->m_cHelper->gfGetCurrentLocalDate()." 003")
																																							->push($this->m_cHelper->gfGetCurrentLocalDate()." 004")
																																							->push($this->m_cHelper->gfGetCurrentLocalDate()." 005")
																																							->push($this->m_cHelper->gfGetCurrentLocalDate()." 006")
																																							->push($this->m_cHelper->gfGetCurrentLocalDate()." 007")
																																							->push($this->m_cHelper->gfGetCurrentLocalDate()." 008")
																																							->push($this->m_cHelper->gfGetCurrentLocalDate()." 009")
																									]
												]
												,kill:false
											);

			$this->m_cHelper->gfGetRedis()->list("xxx.list")->for_each
			(
				function ($v,$list_length) 
				{
					echo " be.x.x. redis server => list length : $list_length current pop value : $v\n";
				}
			);
		}
	}